__author__ = 'fingul'

from mytree.catalog.models import *

import os
from os.path import join, getsize, normpath

def add(szroot = 'c:/dir'):
    szroot = os.path.normpath(szroot)
    d = {}
    for dirpath, dirnames, filenames in os.walk(szroot):
        #print os.path.normpath(dirpath), dirnames, filenames
        szbase = normpath(dirpath)
        parent = d.get(szbase,None)
        for dirname in dirnames:
            szkey = normpath(join(dirpath,dirname))
            #print szkey

            sznode = dirname.decode('cp949','ignore')

            node = Category(parent=parent,name=sznode)
            node.save()
            d[szkey] = node
            #print '%(node)r = add(%(parent)r, %(sznode)r)'%locals()

#d.items()
